<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺类型" prop="passFlag">
        <dict-select :options="dict.type.audit_type" v-model="queryParams.passFlag" placeholder="请选择审核状态" />
      </el-form-item>
      <el-form-item label="用户类型" prop="passFlag">
        <dict-select :options="dict.type.audit_type" v-model="queryParams.passFlag" placeholder="请选择审核状态" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain icon="el-icon-upload2" size="mini" @click="handleQuery">导出订单列表</el-button>
        <el-button icon="el-icon-download" size="mini" @click="resetQuery" type="success" plain>导入订单列表</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="applyList">
      <el-table-column label="商品订单号" align="left" prop="userName"  width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="商品列表" align="left" prop="userRandomId"  width="160" :show-overflow-tooltip="true">
        <template slot-scope="">
          <div>
            <span>店铺余额：</span>
          </div>
          <div>
            <span>店铺充值金额：</span>
          </div>
          <div>
            <span>店铺提现金额：</span>
          </div>
          <div>
            <span>店铺充提差：</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="件数" align="left" prop="shopName"  width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="下单账号" align="left" prop="taskName"  width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="申请时间" align="center" prop="createTime" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="left" prop="shopName"  width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="收货地址" align="left" prop="taskName"  width="160" :show-overflow-tooltip="true">
        <template slot-scope="">
          <div>
            <span>店铺余额：</span>
          </div>
          <div>
            <span>店铺充值金额：</span>
          </div>
          <div>
            <span>店铺提现金额：</span>
          </div>
          <div>
            <span>店铺充提差：</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="物流单号" align="left" prop="taskName"  width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="280">
        <template slot-scope="">
          <div>
            <el-button type="text">退货</el-button>
            <el-button type="text">店主发货</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="直播申请详情" :visible.sync="open" width="1000px" append-to-body class="details-box">
      <el-card>
        <el-row class="details-row" style='font-weight:bold;'>
          <el-col :span="3">直播间名称：</el-col>
          <el-col :span="20">{{detailsObj.shopName}}</el-col>
        </el-row>
        <el-row class="details-row">
          <el-col :span="3">主播姓名：</el-col>
          <el-col :span="20">{{detailsObj.anchorName}}</el-col>
        </el-row>
        <el-row class="details-row">
          <el-col :span="3">申请开播时间：</el-col>
          <el-col :span="20">{{parseTime(detailsObj.startLivesTime)}}</el-col>
        </el-row>
        <el-row class="details-row">
          <el-col :span="3">商家名：</el-col>
          <el-col :span="20">{{detailsObj.shopName}}</el-col>
        </el-row>
        <el-row class="details-row">
          <el-col :span="3">带货任务编号：</el-col>
          <el-col :span="20">{{detailsObj.shopSellTaskId}}</el-col>
        </el-row>
        <el-row class="details-row">
          <el-col :span="3">商品列表</el-col>
<!--          <el-col :span="20">{{detailsObj.shopSellTaskId}}</el-col>-->
        </el-row>
            <el-table :data="detailsObj.goodsChildList">
              <el-table-column label="商品名称" align="center" prop="goodsName" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="原价" align="center" prop="originalPrice" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="现价" align="center" prop="price" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="商品描述" align="center" prop="goodsDesc" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="图片" align="center" prop="image"  width="120" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <oss-image-preview :src="scope.row.image" width="40" height="40"></oss-image-preview>
                </template>
              </el-table-column>
            </el-table>
      </el-card>
    </el-dialog>

  </div>
</template>

<script>
import { listApply, getApply, rejectAudit, passAudit } from '@/api/live/liveAudit'
import { closePass, closeUnPass } from '@/api/store/closeAudit'
import OssImagePreview from '@/components/ImagePreview/oss-image-preview.vue'

export default {
  name: "Apply",
  components: { OssImagePreview },
  dicts:['audit_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主播直播带货申请表格数据
      applyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        anchorName:null,
        shopName:null,
      },
      detailsObj:{},
    };
  },
  created() {
    if (this.$route.query.name) {
      this.queryParams.anchorName = this.$route.query.name
      console.log('this.queryParams.anchorName ,this.queryParams.anchorName ')
    }
    this.getList();
  },
  methods: {
    /** 查询主播直播带货申请列表 */
    getList() {
      this.loading = true;
      listApply(this.queryParams).then(response => {
        this.applyList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //查看详情
    handleDetails:function(row) {
      getApply(row.id).then(response => {
        this.detailsObj = response.data;
        this.open = true;
      });
    },
    //通过
    handlePass:function(row) {
      this.$confirm('同意当前直播申请！', '通过申请', {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(async () => {
        await passAudit(row.id)
        this.$modal.msgSuccess("申请已通过！");
        this.getList()
      }).catch(() => {

      });
    },
    //拒绝
    handleReject:function(row) {
      this.$confirm('拒绝当前直播申请！', '拒绝申请', {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(async ({ value }) => {
        console.log(value)
        await rejectAudit(row.id);
        this.$modal.msgSuccess("拒绝成功！");
        this.getList()
      }).catch(() => {

      });
    },

  }
};
</script>
